<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="common/common_head :: commonHeader('点价物料新增')"/>
    <link th:href="@{/static/css/plugins/cropper/cropper.min.css}" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form class="form-horizontal" method="post" id="InfoForm">
        <div class="row">
            <div class="form-group">
                <div class="col-sm-8" style="margin-left: 16px">
                    <input class="btn btn-primary" type="button" onclick="save()" value="保存">
                    <button class="btn btn-primary" type="button" onclick="Dialog.closeFrame(window.name)">取 消</button>
                </div>
            </div>
            <!-- 显示 隐藏测试 -->
            <ul id="myTab" class="nav nav-tabs">
                <li class="active">
                    <a href="#basicinformation" linkTab="basicinformation" isActive="true" data-toggle="tab"> 基础信息</a>
                </li>
            </ul>
            <!-- 基本信息 -->
            <div id="basicinformation">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-xs-1 control-label"><span class="required-sign">*</span>物料号：</label>
                            <div class="col-xs-3">
                                <input id="materialCode" name="materialCode" type="text" class="form-control required">
                            </div>
                            <label class="col-xs-1 control-label" style="width:220px"><span
                                    class="required-sign">*</span>物料描述：</label>
                            <div class="col-xs-3">
                                <input id="materialDesc" name="materialDes" type="text" class="form-control required">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Chosen -->
<script th:src="@{/static/js/plugins/chosen/chosen.jquery.js}"></script>
<script type="text/javascript">

    $(function () {
        //初始化所有字典数据
        initDictDataSel();
    });

    //保存
    function save() {
        var materialDesc = $("#materialDesc").val();
        var materialCode = $("#materialCode").val();
        if ($("#InfoForm").valid()) {
            Page.ajaxPOST(ctxPath + "/pointPrice/save", {materialCode, materialDesc}, function (res) {
                if (res.code == 0) {
                    Dialog.msg("保存成功!");
                    parent.refresh();
                    Dialog.closeFrame(window.name);
                } else {
                    Dialog.errorMsg(res.result);
                }
            }, {"loadingMsg": "正在往服务器提交数据……"});
        }
    }

    //根据vendorCode查vendorName
    $("#srmCode").change(function () {
        let vendorCode = $(this).val();
        $.ajax({
            url: ctxPath + "/vendor/findById/" + vendorCode,
            type: 'POST',
            dataType: 'JSON',
            success: function (data) {
                if (data.result) {
                    $("#vendorName").val(data.result.vendorName);
                    $("#taxCode").val(data.result.taxCode);
                    $("#currency").val(data.result.orderCurrency);
                } else {
                    Dialog.errorMsg("不存在该供应商，请确认!");
                }
            }
        });
    });

    //根据materialCode查materialDesc
    $("#materialCode").change(function () {
        let materialCode = $(this).val();
        $.ajax({
            url: ctxPath + "/material/getMaterialByCode",
            data: {"materialCode": materialCode},
            dataType: 'JSON',
            success: function (data) {
                if (data.result) {
                    $("#materialDesc").val(data.result.materialDesc);
                    $("#purchaseUnit").val(data.result.basicUnit);
                } else {
                    Dialog.errorMsg("不存在该物料，请确认!");
                }
            }
        });
    });
</script>

</body>
</html>
